//横向堆叠柱状图-异常
function DRAWCROSSSTA(url,modelSend,drawContainer,drillValue,drillUrl) {
    this.draw = function () {
        console.log(modelSend);
        $.ajax({ type: "post",
            url: url,
            dataType: "json",
            data: {"paramData":JSON.stringify(modelSend)},
            success: function (result) {
                console.log(result);
                var str="";
                if(result.front) {
                    for (var i = 0; i < result.front.length; i++) {
                        str += '<p class="titleSub">' + result.front[i].label + '' +
                            '<span>' + result.front[i].value + '</span></p>';
                    }
                }
                $("#text_h4").html(result.titledate+"月");
                $("#summarizing").html(str);
                var dcInstance= new DRAWCCHART(result,drawContainer,drillValue,drillUrl,JSON.stringify(modelSend));
                dcInstance.draw(result,drawContainer,drillValue,drillUrl,JSON.stringify(modelSend));
            },
            error: function (err) {
                console.log(err);
            }});
    };
};
//定义一个用于绘制图形的类
function DRAWCCHART(json,drawContainer,drillValue,drillUrl,modelSend){
    //坐标轴的颜色
    this.colorg=['#357FB7','#D95550','#9AC062'];
    //根据得到的数据绘制Y轴
    this.setYaxis=function(data){
        var yaxArray=[];
        for(var i=0;i<data.axis.yCnt;i++){
            var k=i;
            var obj={labels:{format:'{value}',style:{color:''}},title:{text:''}};
            obj.labels.style.color =this.colorg[k];
            if(data.theme.yAxis[k].align=='right'||data.theme.yAxis[k].opposite=='false'){
                obj.labels.format='{value}%';
                obj.opposite='true';
            }
            yaxArray.push(obj);
        }
        return yaxArray;
    };
    //根据得到的数据设置指标
    this.setSeries=function(dataSource){
        var serArray=[];
        for(var key in dataSource.data){
            var obj={};
            var mun=dataSource.data[key].yAxis;
            obj.type=dataSource.theme.yAxis[mun].type=='line'?'line':'column';
            obj.name=dataSource.data[key].label;
            obj.data=dataSource.data[key].value;
            obj.color=this.colorg[key];
            obj.zIndex=dataSource.theme.yAxis[mun].type=='line'?1:0;
            obj.yAxis=dataSource.data[key].yAxis;
            obj.dataLabels={enabled: false,//堆图默认提示文字
                color: '#000000'};
            serArray.push(obj);
        }
        return serArray;
    };
    //绘制堆叠柱状图的方法
    this.draw=function(json,container){
        var option={
            chart: {
                type: 'bar' , //纵向堆图
                padding:[20,10,20,10]
            },
            title: {
                text: ''     // 标题
            },
            xAxis: {
                categories: json.axis.x   // x 轴分类
            },
            yAxis:this.setYaxis(json),
            tooltip: {
                useHTML:true,
                pointFormat:
                    '<div style="width: 140px;"><span style="color:{series.color};float:left">{series.name}</span>:<span style="float: right"> <b>{point.y}</b> ({point.percentage:.2f}%)</span><br/></div>',
                shared: true
            },
            plotOptions: {
                column: {stacking: 'normal'},
                series:{
                    events:{
                        legendItemClick:function(e){
                            if(drillValue) {
                                var lab=e.target.name;
                                console.log(e.target);
                                var str=drillUrl+'?lab='+lab+'&modelSend='+modelSend;
                                window.open(str,'_self');
                            }
                        }
                    }
                }

            },
            legend:{
                align: 'center',
                verticalAlign: 'top'
            },
            credits: {//隐藏官网提示
                enabled: false
            },
            exporting: {
                chartOptions: {
                    plotOptions: {
                        series: {
                            dataLabels: {
                                enabled: true
                            }
                        }
                    }
                }
            },
            series:this.setSeries(json)
        };
        Highcharts.setOptions({
            lang: {printChart:"打印图表",
                downloadJPEG: "下载JPEG 图片" ,
                downloadPDF: "下载PDF文档"  ,
                downloadPNG: "下载PNG 图片"  ,
                downloadSVG: "下载SVG 矢量图" ,
                exportButtonTitle: "导出图片"
            }
        });
        Highcharts.chart(container,option);
    };
}